﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Greve.Forms
{
	public partial class AddJudge : Form
	{
		public bool _cancel = false;
		public bool keyPressed = false;

		public Judge judge;

		public AddJudge()
		{
			judge = new Judge();
			InitializeComponent();

			this.KeyPreview = true;
			this.KeyDown += new KeyEventHandler(AddJudge_KeyDown);
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
			if (judge._name.Equals("") && judge._ID != -1)
				MessageBox.Show("Missing name or ID for judge.", "Error");
			else
				this.Close();
		}

		private void IDBox(object sender, KeyPressEventArgs e)
		{
			if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
			{
				e.Handled = true;
			}
		}

		private void buttonCancel_Click(object sender, EventArgs e)
		{
			_cancel = true;
			this.Close();
		}

		private void textBox1_TextChanged(object sender, EventArgs e)
		{
			judge._name = textBox1.Text;
		}

		private void textBox2_TextChanged(object sender, EventArgs e)
		{
			if (!textBox2.Text.Equals(""))
			{
				judge._ID = int.Parse(textBox2.Text);
			}
		}

		private void AddJudge_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Control && e.KeyCode.Equals(Keys.N) && !keyPressed)
			{
				e.Handled = true;
				e.SuppressKeyPress = true;
				keyPressed = true;
				textBox1.Focus();
			}
			if(e.Control && e.KeyCode.Equals(Keys.I) && !keyPressed)
			{
				e.Handled = true;
				e.SuppressKeyPress = true;
				keyPressed = true;
				textBox2.Focus();
			}
		}

		private void AddJudge_KeyUp(object sender, KeyEventArgs e)
		{
			keyPressed = false;
		}
	}
}
